﻿namespace HostTracker.Azure.Management

open System
open System.ServiceModel

[<Interface>]
[<ServiceContractAttribute>]
type IServiceManagement = 
    inherit ISubscribtionManagement
    inherit IOSManagement
    inherit IStorageManagement
    inherit IHostedServiceManagement
    inherit IDeploymentManagement
    inherit IAffinityGroupManagement
    inherit IAsyncOperationManagement
    inherit ICertificatesManagement

module AsyncOperationManagement = 
    let Check(requestId: string) : CloudResponce<OperationResult, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2009-10-01" (fun channel -> channel.Check(requestId))
    let CheckAsync(requestId: string): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2009-10-01" (fun channel (rc, s) -> channel.BeginCheck(requestId, rc, s)),
            x.AsyncEnd(fun channel -> channel.EndCheck))
        }
    let CheckTask(requestId: string) = CheckAsync(requestId) |> Async.StartAsTask
    let CheckWith (x: BaseManagement<IServiceManagement>) (requestId: string) : CloudResponce<OperationResult, ServiceManagementError> = 
        x.Sync false "2009-10-01" (fun channel -> channel.Check(requestId))
    let CheckWithAsync (x: BaseManagement<IServiceManagement>) (requestId: string): Async<CloudResponce<_, ServiceManagementError>> =
        Async.FromBeginEnd(
            x.AsyncBegin false "2009-10-01" (fun channel (rc, s) -> channel.BeginCheck(requestId, rc, s)),
            x.AsyncEnd(fun channel -> channel.EndCheck))
    let CheckWithTask (x: BaseManagement<IServiceManagement>) (requestId: string) = CheckWithAsync (x: BaseManagement<IServiceManagement>) (requestId) |> Async.StartAsTask

module SubscriptionManagement =
    let Get(id:string): CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(false)
        x.Sync false "2011-10-01" (fun channel -> channel.GetSubscribtion(id))
    let GetAsync(id:string): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(false)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2011-10-01" (fun channel (rc, s) -> channel.BeginGetSubscribtion(id, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndGetSubscribtion))
        }
    let GetTask(id) = GetAsync(id) |> Async.StartAsTask
    let MySubscriptionId = BaseManagement<IServiceManagement>.SubscribtionId

module OSManagement = 
    let GetAll() : CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2010-10-28" (fun channel -> channel.ListOperatingSystems())
    let GetAllAsync(): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2010-10-28" (fun channel -> channel.BeginListOperatingSystems),
            x.AsyncEnd (fun channel -> channel.EndListOperatingSystems))
        }
    let GetAllTask() = GetAllAsync() |> Async.StartAsTask
    let GetAllFamilies(): CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2010-10-28" (fun  channel -> channel.ListOperatingSystemFamilies())
    let GetAllFamiliesAsync(): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2010-10-28" (fun channel -> channel.BeginListOperatingSystemFamilies),
            x.AsyncEnd (fun channel -> channel.EndListOperatingSystemFamilies))
        }
    let GetAllFamiliesTask() = GetAllFamiliesAsync() |> Async.StartAsTask

module AffinityGroupAndLocationManagement = 
    let GetAll(): CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2009-10-01" (fun channel -> channel.ListAffinityGroups())
    let Get(groupName:string): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2009-10-01" (fun channel -> channel.GetAffinityGroup(groupName))
    let Create(creation: AffinityGroupCreation): CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2011-02-25" (fun channel -> channel.CreateAffinityGroup(creation))
    let Delete(groupName: string): CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2011-02-25" (fun channel -> channel.DeleteAffinityGroup(groupName))
    let Update(groupName: string, updating: AffinityGroupUpdate): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2011-02-25" (fun channel -> channel.UpdateAffinityGroup(groupName, updating))
    let GetAllAsync(): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2009-10-01" (fun channel -> channel.BeginListAffinityGroups),
            x.AsyncEnd <| fun channel -> channel.EndListAffinityGroups)        
        }
    let GetAllTask() = GetAllAsync() |> Async.StartAsTask    
    let GetAsync(groupName:string): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2009-10-01" (fun channel (rc, s) -> channel.BeginGetAffinityGroup(groupName, rc, s)),
            x.AsyncEnd <| fun channel -> channel.EndGetAffinityGroup)
        }
    let GetTask(groupName:string) = GetAsync(groupName) |> Async.StartAsTask     
    let CreateAsync(creation: AffinityGroupCreation): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2011-02-25" (fun channel (rc, s) -> channel.BeginCreateAffinityGroup(creation, rc, s)),
            x.AsyncEnd <| fun channel -> channel.EndCreateAffinityGroup)
        }
    let CreateTask(creation: AffinityGroupCreation) = CreateAsync(creation) |> Async.StartAsTask    
    let DeleteAsync(groupName: string): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2011-02-25" (fun channel (rc, s) -> channel.BeginDeleteAffinityGroup(groupName, rc, s)),
            x.AsyncEnd <| fun channel -> channel.EndDeleteAffinityGroup)
        }
    let DeleteTask(groupName: string) = DeleteAsync(groupName) |> Async.StartAsTask
    let UpdateAsync(groupName: string, updating: AffinityGroupUpdate): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2011-02-25" (fun channel (rc, s) -> channel.BeginUpdateAffinityGroup(groupName, updating, rc, s)),
            x.AsyncEnd <| fun channel -> channel.EndUpdateAffinityGroup)
        }
    let UpdateTask(groupName: string, updating: AffinityGroupUpdate) = UpdateAsync(groupName, updating) |> Async.StartAsTask
    let GetAllLocations(): CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2010-10-28" (fun channel -> channel.ListLocations())
    let GetAllLocationsAsync(): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2010-10-28" (fun channel -> channel.BeginListLocations),
            x.AsyncEnd(fun channel -> channel.EndListLocations))
        }
    let GetAllLocationsTask() = GetAllLocationsAsync() |> Async.StartAsTask

module HostedServiceManagement = 
    let GetAll() : CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2009-10-01" (fun channel -> channel.ListHostedServices())
    let GetAllAsync() : Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2009-10-01" (fun channel -> channel.BeginListHostedServices),
            x.AsyncEnd (fun channel -> channel.EndListHostedServices))
        }
    let GetAllTask = GetAllAsync >> Async.StartAsTask
    let Get(serviceName: string, withDetails: bool): CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2011-10-01" (fun channel -> channel.GetHostedService(serviceName, withDetails))
    let GetAsync(serviceName: string, withDetails: bool) : Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2011-10-01" (fun channel (rc, s) -> channel.BeginGetHostedService(serviceName, withDetails, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndGetHostedService))
        }
    let GetTask = GetAsync >> Async.StartAsTask    
    let CreateWithAffinityGroup(creation:HostedServiceCreationWithAffinityGroup) : CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2010-10-28" (fun channel -> channel.CreateHostedServiceWithAffinityGroup(creation))
    let CreateWithAffinityGroupAsync(creation: HostedServiceCreationWithAffinityGroup) : Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2010-10-28" (fun channel (rc, s) -> channel.BeginCreateHostedServiceWithAffinityGroup(creation, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndCreateHostedServiceWithAffinityGroup))
        }
    let CreateWithAffinityGroupTask(creation) = CreateWithAffinityGroupAsync(creation) |> Async.StartAsTask
    let CreateInLocation(creation:HostedServiceCreationWithLocation) : CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2010-10-28" (fun channel -> channel.CreateHostedServiceInLocation(creation))
    let CreateInLocationAsync(creation: HostedServiceCreationWithLocation) : Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2010-10-28" (fun channel (rc, s) -> channel.BeginCreateHostedServiceInLocation(creation, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndCreateHostedServiceInLocation))
        } 
    let CreateInLocationTask(creation) = CreateInLocationAsync(creation) |> Async.StartAsTask
    let Delete(serviceName): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2010-10-28" (fun channel -> channel.DeleteHostedService(serviceName))
    let DeleteAsync(serviceName): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2010-10-28" (fun channel (rc, s) -> channel.BeginDeleteHostedService(serviceName, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndDeleteHostedService))
        }
    let DeleteTask = DeleteAsync >> Async.StartAsTask
    let Update(serviceName: string, update: HostedServiceUpdate): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2010-10-28" (fun channel -> channel.UpdateHostedService(serviceName, update))
    let UpdateAsync(serviceName, update): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2010-20-28" (fun channel (rc, s) -> channel.BeginUpdateHostedService(serviceName, update, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndUpdateHostedService))
        }
    let UpdateTask(serviceName, update) = UpdateAsync(serviceName, update) |> Async.StartAsTask

(*
https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/certificates/<thumbprint-algorithm>-<thumbprint-in-hexadecimal>
*)
/// <summary> Windows Azure management API part wich operates with certificates. 
/// <see cref="http://msdn.microsoft.com/en-us/library/windowsazure/ee795178.aspx">details</see>
/// </summary> 
module CertificatesManagement = 
    let Create(serviceName: string, cert: Certificate): CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2009-10-01" (fun channel -> channel.CreateCertificate(serviceName, cert))
    let CreateAsync(serviceName:string, cert: Certificate): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2009-10-01" (fun channel (rc, s) -> channel.BeginCreateCertificate(serviceName, cert, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndCreateCertificate))
        }
    let CreateTask(serviceName, cert) = CreateAsync(serviceName, cert) |> Async.StartAsTask
    let GetAll(serviceName: string): CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2009-10-01" (fun channel -> channel.ListCertificates(serviceName))
    let GetAllAsync(serviceName: string) : Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2009-10-01" (fun channel (rc, s) -> channel.BeginListCertificates(serviceName, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndListCertificates))
        }
    let GetAllTask = GetAllAsync >> Async.StartAsTask        
    let Get(serviceName: string, alg: string, thumbprint: string): CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2009-10-01" (fun channel -> channel.GetCertificate(serviceName, alg, thumbprint))
    let GetAsync(serviceName:string, alg: string, thumbprint: string): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2009-10-01" (fun channel (rc, s) -> channel.BeginGetCertificate(serviceName, alg, thumbprint, rc, s)),
            x.AsyncEnd(fun channel -> channel.EndGetCertificate))
        }
    let GetTask = GetAsync >> Async.StartAsTask
    let Delete(serviceName: string, alg: string, thumbprint: string): CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2009-10-01" (fun channel -> channel.DeleteCertificate(serviceName,  alg, thumbprint))
    let DeleteAsync(serviceName:string, alg: string, thumbprint: string): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2009-10-01" (fun channel (rc, s) -> channel.BeginDeleteCertificate(serviceName, alg, thumbprint, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndDeleteCertificate))
        }
    let DeleteTask = DeleteAsync >> Async.StartAsTask

module DeploymentManagement =     
    let Create(serviceName:string, deploymentSlot:DeploymentSlot, creation:DeploymentCreation) : CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2011-08-01" (fun channel -> channel.CreateDeployment(serviceName, deploymentSlot.ToString(), creation))
    let CreateAsync(serviceName:string, deploymentSlot:DeploymentSlot, creation:DeploymentCreation) 
        : Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2011-08-01" (fun channel (rc, s) -> channel.BeginCreateDeployment(serviceName, deploymentSlot.ToString(), creation, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndCreateDeployment))
        }
    let CreateTask(serviceName, deploymentSlot, creation) = CreateAsync(serviceName, deploymentSlot, creation) |> Async.StartAsTask    

    let Get(serviceName:string, deploymentSlot:DeploymentSlot) : CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2011-10-01" (fun channel -> channel.GetDeploymentInSlot(serviceName, deploymentSlot.ToString()))
    let GetAsync(serviceName:string, deploymentSlot:DeploymentSlot) : Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2011-10-01" (fun channel (rc, s) -> channel.BeginGetDeploymentInSlot(serviceName, deploymentSlot.ToString(), rc, s)),
            x.AsyncEnd (fun channel -> channel.EndGetDeploymentInSlot))
        }
    let GetTask(serviceName:string, deploymentSlot:DeploymentSlot) =
        GetAsync(serviceName, deploymentSlot) |> Async.StartAsTask

    let GetByName(serviceName:string, deploymentName:string) : CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2011-10-01" (fun channel -> channel.GetDeploymentInSlot(serviceName, deploymentName))
    let GetByNameAsync(serviceName:string, deploymentName: string) : Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2011-10-01" (fun channel (rc, s) -> channel.BeginGetDeploymentByName(serviceName, deploymentName, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndGetDeploymentByName))
        }
    let GetByNameTask(serviceName:string, deploymentName:string) =
        GetByNameAsync(serviceName, deploymentName) |> Async.StartAsTask

    let ChangeConfiguration(serviceName:string, deploymentSlot:DeploymentSlot, configChanging:ConfigurationChanging) : CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2011-08-01" (fun channel -> 
            channel.ChangeDeploymentConfigurationInSlot(serviceName, deploymentSlot.ToString(), configChanging))
    let ChangeConfigurationAsync(serviceName:string, deploymentSlot:DeploymentSlot, configChanging:ConfigurationChanging) 
        : Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2011-08-01" (fun channel (rc, s) -> channel.BeginChangeDeploymentConfigurationInSlot(serviceName, deploymentSlot.ToString(), configChanging, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndChangeDeploymentConfigurationInSlot))
        }
    let ChangeConfigurationTask(serviceName:string, deploymentSlot:DeploymentSlot, configChanging:ConfigurationChanging)  = 
        ChangeConfigurationAsync(serviceName, deploymentSlot, configChanging) |> Async.StartAsTask

    let ChangeConfigurationByName(serviceName:string, deploymentName:string, configChanging:ConfigurationChanging) : CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2011-08-01" (fun channel -> 
            channel.ChangeDeploymentConfigurationByName(serviceName, deploymentName, configChanging))
    let ChangeConfigurationByNameAsync(serviceName:string, deploymentName:string, configChanging:ConfigurationChanging) 
        : Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2011-08-01" (fun channel (rc, s) -> channel.BeginChangeDeploymentConfigurationByName(serviceName, deploymentName, configChanging, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndChangeDeploymentConfigurationInSlot))
        }
    let ChangeConfigurationByNameTask(serviceName:string, deploymentName: string, configChanging:ConfigurationChanging)  = 
        ChangeConfigurationByNameAsync(serviceName, deploymentName, configChanging) |> Async.StartAsTask

    let UpgradeAllRoles(serviceName:string, deploymentSlot:DeploymentSlot, upgrade: DeploymentGlobalUpgarde): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2011-10-01" (fun channel -> channel.UpgradeAllDeploymentRolesInSlot(serviceName, deploymentSlot.ToString(), upgrade))
    let UpgradeAllRolesAsync(serviceName:string, deploymentSlot:DeploymentSlot, upgrade: DeploymentGlobalUpgarde): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2011-10-01" (fun channel (rc, s) -> channel.BeginUpgradeAllDeploymentRolesInSlot(serviceName, deploymentSlot.ToString(), upgrade, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndUpgradeAllDeploymentRolesInSlot))
        }
    let UpgradeAllRolesTask(serviceName:string, deploymentSlot:DeploymentSlot, upgrade: DeploymentGlobalUpgarde) =        
        UpgradeAllRolesAsync(serviceName, deploymentSlot, upgrade) |> Async.StartAsTask

    let UpgradeAllRolesByName(serviceName:string, deploymentName: string, upgrade: DeploymentGlobalUpgarde): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2011-10-01" (fun channel -> channel.UpgradeAllDeploymentRolesByName(serviceName, deploymentName, upgrade))
    let UpgradeAllRolesByNameAsync(serviceName:string, deploymentName: string, upgrade: DeploymentGlobalUpgarde): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2011-10-01" (fun channel (rc, s) -> channel.BeginUpgradeAllDeploymentRolesByName(serviceName, deploymentName, upgrade, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndUpgradeAllDeploymentRolesByName))
        }
    let UpgradeAllRolesByNameTask(serviceName:string, deploymentName:string, upgrade: DeploymentGlobalUpgarde) =
        UpgradeAllRolesByNameAsync(serviceName, deploymentName, upgrade) |> Async.StartAsTask

    let UpgradeRole(serviceName:string, deploymentSlot:DeploymentSlot, upgrade: DeploymentRoleUpgarde): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2011-10-01" (fun channel -> channel.UpgradeDeploymentRoleInSlot(serviceName, deploymentSlot.ToString(), upgrade))
    let UpgradeRoleAsync(serviceName:string, deploymentSlot:DeploymentSlot, upgrade: DeploymentRoleUpgarde): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2011-10-01" (fun channel (rc, s) -> channel.BeginUpgradeDeploymentRoleInSlot(serviceName, deploymentSlot.ToString(), upgrade, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndUpgradeDeploymentRoleInSlot))
        }
    let UpgradeRoleTask(serviceName:string, deploymentSlot:DeploymentSlot, upgrade: DeploymentRoleUpgarde) =
        UpgradeRoleAsync(serviceName, deploymentSlot, upgrade) |> Async.StartAsTask

    let UpgradeRoleByDeploymentName(serviceName:string, deploymentName: string, upgrade: DeploymentRoleUpgarde): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2011-10-01" (fun channel -> channel.UpgradeDeploymentRoleByName(serviceName, deploymentName, upgrade))
    let UpgradeRoleByDeploymentNameAsync(serviceName:string, deploymentName: string, upgrade: DeploymentRoleUpgarde): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2011-10-01" (fun channel (rc, s) -> channel.BeginUpgradeDeploymentRoleByName(serviceName, deploymentName, upgrade, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndUpgradeDeploymentRoleInSlot))
        }
    let UpgradeRoleByDeploymentNameTask(serviceName:string, deploymentName: string, upgrade: DeploymentRoleUpgarde) =
        UpgradeRoleByDeploymentNameAsync(serviceName, deploymentName, upgrade) |> Async.StartAsTask

    let Delete(serviceName:string, deploymentSlot: DeploymentSlot): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2009-10-01" (fun channel -> channel.DeleteDeploymentInSlot(serviceName, deploymentSlot.ToString()))
    let DeleteAsync(serviceName:string, deploymentSlot: DeploymentSlot): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2009-10-01" (fun channel (rc, s) -> channel.BeginDeleteDeploymentInSlot(serviceName, deploymentSlot.ToString(), rc, s)),
            x.AsyncEnd (fun channel -> channel.EndDeleteDeploymentInSlot))
        }
    let DeleteTask(serviceName:string, deploymentSlot: DeploymentSlot) =
        DeleteAsync(serviceName, deploymentSlot) |> Async.StartAsTask

    let DeleteByName(serviceName:string, deploymentName: string): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2009-10-01" (fun channel -> channel.DeleteDeploymentByName(serviceName, deploymentName))
    let DeleteByNameAsync(serviceName:string, deploymentName: string): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2009-10-01" (fun channel (rc, s) -> channel.BeginDeleteDeploymentByName(serviceName, deploymentName, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndDeleteDeploymentByName))
        }
    let DeleteByNameTask(serviceName:string, deploymentName: string) =
        DeleteByNameAsync(serviceName, deploymentName) |> Async.StartAsTask

    let Swap(serviceName:string, swap: DeploymentSwap): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2009-10-01" (fun channel -> channel.SwapDeployments(serviceName, swap))
    let SwapAsync(serviceName:string, swap: DeploymentSwap): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2009-10-01" (fun channel (rc, s) -> channel.BeginSwapDeployments(serviceName, swap, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndSwapDeployments))
        }
    let SwapTask(serviceName:string, swap) = SwapAsync(serviceName, swap) |> Async.StartAsTask

    let ChangeStatus(serviceName:string, deploymentSlot:DeploymentSlot, update: DeploymentStatusUpdate): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2009-10-01" (fun channel -> channel.UpdateDeploymentStatusInSlot(serviceName, deploymentSlot.ToString(), update))
    let ChangeStatusAsync(serviceName:string, deploymentSlot:DeploymentSlot, update: DeploymentStatusUpdate): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2009-10-01" (fun channel (rc, s) -> channel.BeginUpdateDeploymentStatusInSlot(serviceName, deploymentSlot.ToString(), update, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndUpdateDeploymentStatusInSlot))
        }
    let ChangeStatusTask(serviceName:string, deploymentSlot:DeploymentSlot, update: DeploymentStatusUpdate) =
        ChangeStatusAsync(serviceName, deploymentSlot, update) |> Async.StartAsTask

    let ChangeStatusByName(serviceName:string, deploymentName, update: DeploymentStatusUpdate): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2009-10-01" (fun channel -> channel.UpdateDeploymentStatusByName(serviceName, deploymentName, update))
    let ChangeStatusByNameAsync(serviceName:string, deploymentName, update: DeploymentStatusUpdate): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2009-10-01" (fun channel (rc, s) -> channel.BeginUpdateDeploymentStatusByName(serviceName, deploymentName, update, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndUpdateDeploymentStatusByName))
        }
    let ChangeStatusByNameTask(serviceName:string, deploymentName: string, update: DeploymentStatusUpdate) =
        ChangeStatusByNameAsync(serviceName, deploymentName, update) |> Async.StartAsTask

    let WalkUpgradeDomain(serviceName:string, deploymentSlot:DeploymentSlot, walk: UpgradeDomainWalk): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2009-10-01" (fun channel -> channel.WalkUpgradeDomainInSlot(serviceName, deploymentSlot.ToString(), walk))
    let WalkUpgradeDomainAsync(serviceName:string, deploymentSlot:DeploymentSlot, walk: UpgradeDomainWalk): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2009-10-01" (fun channel (rc, s) -> channel.BeginWalkUpgradeDomainInSlot(serviceName, deploymentSlot.ToString(), walk, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndWalkUpgradeDomainInSlot))
        }
    let WalkUpgradeDomainTask(serviceName:string, deploymentSlot:DeploymentSlot, walk: UpgradeDomainWalk) =
        WalkUpgradeDomainAsync(serviceName, deploymentSlot, walk) |> Async.StartAsTask

    let WalkUpgradeDomainByName(serviceName:string, deploymentName, walk: UpgradeDomainWalk): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2009-10-01" (fun channel -> channel.WalkUpgradeDomainByName(serviceName, deploymentName, walk))
    let WalkUpgradeDomainByNameAsync(serviceName:string, deploymentName, walk: UpgradeDomainWalk): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2009-10-01" (fun channel (rc, s) -> channel.BeginWalkUpgradeDomainByName(serviceName, deploymentName, walk, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndWalkUpgradeDomainByName))
        }
    let WalkUpgradeDomainByNameTask(serviceName:string, deploymentName: string, walk: UpgradeDomainWalk) =
        WalkUpgradeDomainByNameAsync(serviceName, deploymentName, walk) |> Async.StartAsTask

    let RebootRoleInstance(serviceName:string, deploymentSlot:DeploymentSlot, roleInstanceName: string): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2010-10-28" (fun channel -> channel.RebootDeploymentRoleInstanceInSlot(serviceName, deploymentSlot.ToString(), roleInstanceName))
    let RebootRoleInstanceAsync(serviceName:string, deploymentSlot:DeploymentSlot, roleInstanceName: string): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2010-10-28" (fun channel (rc, s) -> channel.BeginRebootDeploymentRoleInstanceInSlot(serviceName, deploymentSlot.ToString(), roleInstanceName, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndRebootDeploymentRoleInstanceInSlot))
        }
    let RebootRoleInstanceTask(serviceName:string, deploymentSlot:DeploymentSlot, roleInstanceName: string) =
        RebootRoleInstanceAsync(serviceName, deploymentSlot, roleInstanceName) |> Async.StartAsTask

    let RebootRoleInstanceByName(serviceName:string, deploymentName, roleInstanceName: string): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2010-10-28" (fun channel -> channel.RebootDeploymentRoleInstanceByName(serviceName, deploymentName, roleInstanceName))
    let RebootRoleInstanceByNameAsync(serviceName:string, deploymentName, roleInstanceName: string): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2010-10-28" (fun channel (rc, s) -> channel.BeginRebootDeploymentRoleInstanceByName(serviceName, deploymentName, roleInstanceName, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndRebootDeploymentRoleInstanceByName))
        }
    let RebootRoleInstanceByNameTask(serviceName:string, deploymentName: string, roleInstanceName: string) =
        RebootRoleInstanceByNameAsync(serviceName, deploymentName, roleInstanceName) |> Async.StartAsTask

    let ReimageRoleInstance(serviceName:string, deploymentSlot:DeploymentSlot, roleInstanceName: string): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2010-10-28" (fun channel -> channel.ReimageDeploymentRoleInstanceInSlot(serviceName, deploymentSlot.ToString(), roleInstanceName))
    let ReimageRoleInstanceAsync(serviceName:string, deploymentSlot:DeploymentSlot, roleInstanceName: string): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2010-10-28" (fun channel (rc, s) -> channel.BeginReimageDeploymentRoleInstanceInSlot(serviceName, deploymentSlot.ToString(), roleInstanceName, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndReimageDeploymentRoleInstanceInSlot))
        }
    let ReimageRoleInstanceTask(serviceName:string, deploymentSlot:DeploymentSlot, roleInstanceName: string) =
        ReimageRoleInstanceAsync(serviceName, deploymentSlot, roleInstanceName) |> Async.StartAsTask

    let ReimageRoleInstanceByName(serviceName:string, deploymentName, roleInstanceName: string): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2010-10-28" (fun channel -> channel.ReimageDeploymentRoleInstanceByName(serviceName, deploymentName, roleInstanceName))
    let ReimageRoleInstanceByNameAsync(serviceName:string, deploymentName: string, roleInstanceName: string): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2010-10-28" (fun channel (rc, s) -> channel.BeginReimageDeploymentRoleInstanceByName(serviceName, deploymentName, roleInstanceName, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndReimageDeploymentRoleInstanceByName))
        }
    let ReimageRoleInstanceByNameTask(serviceName:string, deploymentName: string, roleInstanceName: string) =
        ReimageRoleInstanceByNameAsync(serviceName, deploymentName, roleInstanceName) |> Async.StartAsTask

    let Rollback(serviceName:string, deploymentSlot:DeploymentSlot, rollback: DeploymentRollback): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2011-10-01" (fun channel -> channel.RollbackDeploymentUpgradeInSlot(serviceName, deploymentSlot.ToString(), rollback))
    let RollbackAsync(serviceName:string, deploymentSlot:DeploymentSlot, rollback: DeploymentRollback): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2011-10-01" (fun channel (rc, s) -> channel.BeginRollbackDeploymentUpgradeInSlot(serviceName, deploymentSlot.ToString(), rollback, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndRollbackDeploymentUpgradeInSlot))
        }
    let RollbackTask(serviceName:string, deploymentSlot:DeploymentSlot, rollback) =
        RollbackAsync(serviceName, deploymentSlot, rollback) |> Async.StartAsTask

    let RollbackByName(serviceName:string, deploymentName, rollback): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2011-10-01" (fun channel -> channel.RollbackDeploymentUpgradeByName(serviceName, deploymentName, rollback))
    let RollbackByNameAsync(serviceName:string, deploymentName: string, rollback: DeploymentRollback): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2011-10-01" (fun channel (rc, s) -> channel.BeginRollbackDeploymentUpgradeByName(serviceName, deploymentName, rollback, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndRollbackDeploymentUpgradeByName))
        }
    let RollbackByNameTask(serviceName:string, deploymentName: string, rollback) =
        RollbackByNameAsync(serviceName, deploymentName, rollback) |> Async.StartAsTask
    (* long running operations *)
    let CreateAsLongRunningAsync (serviceName:string, deploymentSlot:DeploymentSlot, creation:DeploymentCreation, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(CreateAsync(serviceName, deploymentSlot, creation), AsyncOperationManagement.CheckWithAsync x, handlers)
        }
    let SwapAsLongRunningAsync (serviceName, swap, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(SwapAsync(serviceName, swap), AsyncOperationManagement.CheckWithAsync x, handlers)
        }
    let DeleteAsLongRunningAsync (serviceName, slot: DeploymentSlot, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(DeleteAsync(serviceName, slot), AsyncOperationManagement.CheckWithAsync x, handlers)
        }
    let DeleteByNameAsLongRunningAsync (serviceName, name: string, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(DeleteByNameAsync(serviceName, name), AsyncOperationManagement.CheckWithAsync x, handlers)
        }
    let ChangeConfigurationAsLongRunningAsync (serviceName, slot: DeploymentSlot, config, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(ChangeConfigurationAsync(serviceName, slot, config), AsyncOperationManagement.CheckWithAsync x, handlers)
        }
    let ChangeConfigurationByNameAsLongRunningAsync (serviceName, name:string, config, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(ChangeConfigurationByNameAsync(serviceName, name, config), AsyncOperationManagement.CheckWithAsync x, handlers)
        }
    let ChangeStatusAsLongRunningAsync (serviceName: string, slot: DeploymentSlot, update: DeploymentStatusUpdate, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(ChangeStatusAsync(serviceName, slot, update), AsyncOperationManagement.CheckWithAsync x, handlers)
        }
    let ChangeStatusByNameAsLongRunningAsync (serviceName, name:string, update, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(ChangeStatusByNameAsync(serviceName, name, update), AsyncOperationManagement.CheckWithAsync x, handlers)
        }
    let UpgradeAllAsLongRunningAsync (serviceName: string, slot: DeploymentSlot, upgrade, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(UpgradeAllRolesAsync(serviceName, slot, upgrade), AsyncOperationManagement.CheckWithAsync x, handlers)
        }
    let UpgradeAllByNameAsLongRunningAsync (serviceName, name:string, upgrade, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(UpgradeAllRolesByNameAsync(serviceName, name, upgrade), AsyncOperationManagement.CheckWithAsync x, handlers)
        }
    let UpgradeOneAsLongRunningAsync (serviceName: string, slot: DeploymentSlot, upgrade, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(UpgradeRoleAsync(serviceName, slot, upgrade), AsyncOperationManagement.CheckWithAsync x, handlers)
        }
    let UpgradeOneByNameAsLongRunningAsync (serviceName, name:string, upgrade, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(UpgradeRoleByDeploymentNameAsync(serviceName, name, upgrade), AsyncOperationManagement.CheckWithAsync x, handlers)    
        }
    let WalkDomainAsLongRunningAsync (serviceName: string, slot: DeploymentSlot, walk: UpgradeDomainWalk, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(WalkUpgradeDomainAsync(serviceName, slot, walk), AsyncOperationManagement.CheckWithAsync x, handlers)
        }
    let WalkDomainByNameAsLongRunningAsync (serviceName, name:string, walk, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(WalkUpgradeDomainByNameAsync(serviceName, name, walk), AsyncOperationManagement.CheckWithAsync x, handlers)    
        }
    let RebootAsLongRunningAsync (serviceName: string, slot: DeploymentSlot, instance: string, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(RebootRoleInstanceAsync(serviceName, slot, instance), AsyncOperationManagement.CheckWithAsync x, handlers)
        }
    let RebootByNameAsLongRunningAsync (serviceName, name:string, instance, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(RebootRoleInstanceByNameAsync(serviceName, name, instance), AsyncOperationManagement.CheckWithAsync x, handlers)    
        }
    let ReimageAsLongRunningAsync (serviceName: string, slot: DeploymentSlot, instance: string, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(ReimageRoleInstanceAsync(serviceName, slot, instance), AsyncOperationManagement.CheckWithAsync x, handlers)
        }
    let ReimageByNameAsLongRunningAsync (serviceName, name:string, instance, handlers) = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! x.StartLongOperation(ReimageRoleInstanceByNameAsync(serviceName, name, instance), AsyncOperationManagement.CheckWithAsync x, handlers)                
        }

    let CreateAsLongRunningTask (serviceName:string, deploymentSlot:DeploymentSlot, creation:DeploymentCreation, handlers) = 
        CreateAsLongRunningAsync (serviceName, deploymentSlot, creation, handlers) |> Async.StartAsTask
    let SwapAsLongRunningTask (serviceName, swap, handlers) = 
        SwapAsLongRunningAsync (serviceName, swap, handlers) |> Async.StartAsTask
    let DeleteAsLongRunningTask (serviceName, slot: DeploymentSlot, handlers) =
        DeleteAsLongRunningAsync (serviceName, slot, handlers) |> Async.StartAsTask
    let DeleteByNameAsLongRunningTask (serviceName, name: string, handlers) = 
        DeleteByNameAsLongRunningAsync (serviceName, name, handlers) |> Async.StartAsTask
    let ChangeConfigurationAsLongRunningTask (serviceName, slot: DeploymentSlot, config, handlers) = 
        ChangeConfigurationAsLongRunningAsync (serviceName, slot, config, handlers) |> Async.StartAsTask
    let ChangeConfigurationByNameAsLongRunningTask (serviceName, name:string, config, handlers) = 
        ChangeConfigurationByNameAsLongRunningAsync(serviceName, name, config, handlers) |> Async.StartAsTask
    let ChangeStatusAsLongRunningTask (serviceName: string, slot: DeploymentSlot, update: DeploymentStatusUpdate, handlers) = 
        ChangeStatusAsLongRunningAsync(serviceName, slot, update, handlers) |> Async.StartAsTask
    let ChangeStatusByNameAsLongRunningTask (serviceName, name:string, update, handlers) = 
        ChangeStatusByNameAsLongRunningAsync (serviceName, name, update, handlers) |> Async.StartAsTask
    let UpgradeAllAsLongRunningTask (serviceName: string, slot: DeploymentSlot, upgrade, handlers) = 
        UpgradeAllAsLongRunningAsync(serviceName, slot, upgrade, handlers) |> Async.StartAsTask
    let UpgradeAllByNameAsLongRunningTask (serviceName, name:string, upgrade, handlers) = 
        UpgradeAllByNameAsLongRunningAsync(serviceName, name, upgrade, handlers) |> Async.StartAsTask
    let UpgradeOneAsLongRunningTask (serviceName: string, slot: DeploymentSlot, upgrade, handlers) = 
        UpgradeOneAsLongRunningAsync (serviceName, slot, upgrade, handlers) |> Async.StartAsTask
    let UpgradeOneByNameAsLongRunningTask (serviceName, name:string, upgrade, handlers) = 
        UpgradeOneByNameAsLongRunningAsync (serviceName, name, upgrade, handlers) |> Async.StartAsTask
    let WalkDomainAsLongRunningTask (serviceName: string, slot: DeploymentSlot, walk: UpgradeDomainWalk, handlers) = 
        WalkDomainAsLongRunningAsync(serviceName, slot, walk, handlers) |> Async.StartAsTask
    let WalkDomainByNameAsLongRunningTask (serviceName, name:string, walk, handlers) = 
        WalkDomainByNameAsLongRunningAsync(serviceName, name, walk, handlers) |> Async.StartAsTask
    let RebootAsLongRunningTask (serviceName: string, slot: DeploymentSlot, instance: string, handlers) = 
        RebootAsLongRunningAsync (serviceName, slot, instance, handlers) |> Async.StartAsTask
    let RebootByNameAsLongRunningTask (serviceName, name:string, instance, handlers) = 
        RebootByNameAsLongRunningAsync (serviceName, name, instance, handlers) |> Async.StartAsTask
    let ReimageAsLongRunningTask (serviceName: string, slot: DeploymentSlot, instance: string, handlers) = 
        ReimageAsLongRunningAsync (serviceName, slot, instance, handlers) |> Async.StartAsTask
    let ReimageByNameAsLongRunningTask (serviceName, name:string, instance, handlers) = 
        ReimageByNameAsLongRunningAsync (serviceName, name, instance, handlers) |> Async.StartAsTask

module StorageManagement = 
    let GetAll() : CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2009-10-01" (fun channel -> channel.ListStorageServices())
    let GetAllAsync() : Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2009-10-01" (fun channel -> channel.BeginListStorageServices),
            x.AsyncEnd (fun channel -> channel.EndListStorageServices))
        }
    let GetAllTask = GetAllAsync >> Async.StartAsTask
    let Get(serviceName:string) : CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2009-10-01" (fun channel -> channel.GetStorageService(serviceName))
    let GetAsync(serviceName:string) : Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2009-10-01" (fun channel (rc, s) -> channel.BeginGetStorageService(serviceName, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndGetStorageService))
        }
    let GetTask = GetAsync >> Async.StartAsTask
    let GetKeys(serviceName: string) : CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2009-10-01" (fun channel -> channel.GetStorageServiceKeys(serviceName))
    let GetKeysAsync(serviceName: string) : Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2009-10-01" (fun channel (rc, s) -> channel.BeginGetStorageServiceKeys(serviceName, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndGetStorageServiceKeys))
        }
    let GetKeysTask = GetKeysAsync >> Async.StartAsTask
    let RegenerateKeys (serviceName: string, keyRegeneration:KeyRegeneration) 
        : CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2009-10-01" (fun channel -> channel.RegenerateStorageServiceKeys(serviceName, keyRegeneration))
    let RegenerateKeysAsync  (serviceName: string, keyRegeneration:KeyRegeneration) 
        : Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2009-10-01" (fun channel (rc, s) -> channel.BeginRegenerateStorageServiceKeys(serviceName, keyRegeneration, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndRegenerateStorageServiceKeys))
        }
    let RegenerateKeysTask(serviceName, keyRegeneration) = RegenerateKeysAsync(serviceName, keyRegeneration) |> Async.StartAsTask
    let CreateInLocation (creation: StorageServiceCreationWithLocation): CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2011-06-01" (fun channel -> channel.CreateStorageServiceInLocation(creation))
    let CreateInLocationAsync (creation: StorageServiceCreationWithLocation)
        : Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2011-06-01" (fun channel (rc, s) -> channel.BeginCreateStorageServiceInLocation(creation, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndCreateStorageServiceInLocation))
        }
    let CreateInLocationTask(creation) = CreateInLocationAsync(creation) |> Async.StartAsTask
    let CreateWithAffinityGroup (creation: StorageServiceCreationWithAffinityGroup): CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2011-06-01" (fun channel -> channel.CreateStorageServiceWithAffinityGroup(creation))
    let CreateWithAffinityGroupAsync (creation: StorageServiceCreationWithAffinityGroup) 
        : Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2011-06-01" (fun channel (rc, s) -> channel.BeginCreateStorageServiceWithAffinityGroup(creation, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndCreateStorageServiceWithAffinityGroup))
        }
    let CreateWithAffinityGroupTask(creation) = CreateWithAffinityGroupAsync(creation) |> Async.StartAsTask
    let Delete (serviceName: string): CloudResponce<_, ServiceManagementError> =
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync false "2011-06-01" (fun channel -> channel.DeleteStorageService(serviceName))
    let DeleteAsync (serviceName: string): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin false "2011-06-01" (fun channel (rc, s) -> channel.BeginDeleteStorageService(serviceName, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndDeleteStorageService))
        }
    let DeleteTask = DeleteAsync >> Async.StartAsTask
    let Update (serviceName: string, update: StorageServiceUpdate) : CloudResponce<_, ServiceManagementError> = 
        use x = new BaseManagement<IServiceManagement>(true)
        x.Sync true "2011-06-01" (fun channel -> channel.UpdateStorageService(serviceName, update))
    let UpdateAsync (serviceName: string, update: StorageServiceUpdate): Async<CloudResponce<_, ServiceManagementError>> = async {
        use x = new BaseManagement<IServiceManagement>(true)
        return! Async.FromBeginEnd(
            x.AsyncBegin true "2011-06-01" (fun channel (rc, s) -> channel.BeginUpdateStorageService(serviceName, update, rc, s)),
            x.AsyncEnd (fun channel -> channel.EndUpdateStorageService))
        }
    let UpdateTask(serviceName, update) = UpdateAsync(serviceName, update) |> Async.StartAsTask 